/**
 * @author yinyunqi
 * @datetime 2018年1月28日
 * @Content 
 */
package com.yongqi.pub;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class BaiduMapTranslate {
	public static String addressTranslate(String lat,String lng) {
		String address = null;
			try {
				URL url = new URL("http://api.map.baidu.com/geocoder/v2/?callback=renderReverse&location="+lat+","+lng+"&output=json&pois=1&ak=LoGzWGFHG3tLBKXRffGTPt5TMLzBXPrn");
				HttpURLConnection connection = (HttpURLConnection) url.openConnection();
				if (connection != null) {
					System.out.println("--------------->百度地图接口连接成功");
					try {
						BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
						String string = null;
						StringBuffer stringBuffer = new StringBuffer();
						while((string = in.readLine())!=null){
							System.out.println(string);
							stringBuffer.append(string);
						}
						address = stringBuffer.toString();
						in.close();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		return address;
	}
}
